package com.jiuli.liping.controller;

import com.jiuli.liping.test.MyAsyncTask;
import com.jiuli.liping.vo.HrmResource;
import com.jiuli.liping.vo.Message;
import com.jiuli.liping.vo.ProductOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jiuli.liping.service.ProductOrderService;

import java.util.List;

/**
 * Author zyl
 * Date  2020-03-25
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/productOrder")
public class ProductOrderController {
    @Autowired
    private ProductOrderService productOrderService;

    @RequestMapping(value = {"/list", ""}, method = RequestMethod.GET)
    public Object list() {
        List<ProductOrder> productOrders = productOrderService.findAllList();
        return productOrders;
    }

    @RequestMapping(value = {"/get"}, method = RequestMethod.GET)
    public Object get(@RequestParam String id) {
        ProductOrder productOrder = productOrderService.get(id);
        return productOrder;
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public String insert(@RequestBody ProductOrder productOrder) {
        if (productOrderService.insert(productOrder) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/insertBatch", method = RequestMethod.POST)
    public String insertBatch(@RequestBody List<ProductOrder> productOrders) {
        if (productOrderService.insertBatch(productOrders) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(@RequestBody ProductOrder productOrder) {
        if (productOrderService.update(productOrder) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    /**
     * 取消订单
     * @param productOrder
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String delete(@RequestBody ProductOrder productOrder) {
        if (productOrderService.delete(productOrder) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    /**
     * 找到该用户下所有订单
     * @param productOrder
     * @return
     */
    @RequestMapping(value = "/findAllListByName", method = RequestMethod.POST)
    public List<ProductOrder> findAllListByName(@RequestBody ProductOrder productOrder) {
        return productOrderService.findAllListByName(productOrder);
    }

    /**
     * 购物车提交订单
     * @param productOrder
     * @return
     */
    @RequestMapping(value = "/submitOrder", method = RequestMethod.POST)
    public Message submitOrder(@RequestBody ProductOrder productOrder) throws InterruptedException{
        Message mes = productOrderService.submitOrder(productOrder);
        return mes;
    }

    /**
     * 直接提交订单
     * @param productOrder
     * @return
     */
    @RequestMapping(value = "/submitOrderOne", method = RequestMethod.POST)
    public Message submitOrderOne(@RequestBody ProductOrder productOrder) throws InterruptedException{
        Message mes = productOrderService.submitOrderOne(productOrder);
        return mes;
    }

    /**
     * 审批通过订单明细
     * @return
     */
    @RequestMapping(value = "/findProductOrderList", method = RequestMethod.POST)
    public List<ProductOrder> findProductOrderList(@RequestBody ProductOrder productOrder) {
        return productOrderService.findProductOrderList(productOrder);
    }

    /**
     * 发货核销数量
     */
    @RequestMapping(value = "/quantityShipped", method = RequestMethod.POST)
    public Message quantityShipped(@RequestBody ProductOrder productOrder) {
        Message me = productOrderService.quantityShipped(productOrder);
        return me;
    }

    /**
     * 发货核销数量星巴克
     */
    @RequestMapping(value = "/quantityShipped2", method = RequestMethod.POST)
    public Message quantityShipped2(@RequestBody ProductOrder productOrder) {
        Message me = productOrderService.quantityShipped2(productOrder);
        return me;
    }

    /**
     * 根据订单号查询审批通过订单
     */
    @RequestMapping(value = "/selectProductOrder", method = RequestMethod.POST)
    public List<ProductOrder> selectProductOrder(@RequestBody ProductOrder productOrder) {
        List<ProductOrder> list = productOrderService.selectProductOrder(productOrder);
        return list;
    }

    /**
     * 核销完结订单信息
     * @return
     */
    @RequestMapping(value = "/findOrderListFinally", method = RequestMethod.POST)
    public List<ProductOrder> findOrderListFinally(@RequestBody ProductOrder productOrder) {
        return productOrderService.findOrderListFinally(productOrder);
    }

    /**
     * 根据订单号查询核销完结订单信息
     */
    @RequestMapping(value = "/findOrderListFinallyByOrderNum", method = RequestMethod.POST)
    public List<ProductOrder> findOrderListFinallyByOrderNum(@RequestBody ProductOrder productOrder) {
        List<ProductOrder> list = productOrderService.findOrderListFinallyByOrderNum(productOrder);
        return list;
    }

    /**
     * 加载领用人信息
     */
    @RequestMapping(value = "/findAllUserName", method = RequestMethod.POST)
    public List<HrmResource> findAllUserName() {
        List<HrmResource> list = productOrderService.findAllUserName();
        return list;
    }

    /**
     * 领用人搜索
     */
    @RequestMapping(value = "/selectUserName", method = RequestMethod.POST)
    public List<HrmResource> selectUserName(@RequestBody String code) {
        List<HrmResource> list = productOrderService.selectUserName(code);
        return list;
    }

    /**
     * 测试接口
     */
    @RequestMapping(value = "/sendEarlyWarning", method = RequestMethod.POST)
    public int sendEarlyWarning(@RequestBody ProductOrder pro) {
        int list = productOrderService.sendEarlyWarning(pro);
        return list;
    }
}
